﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>预约单管理</title>
    <#include "/common/link.ftl">
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="appointment"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>预约单管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/appointment/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label>预约单流水号</label>
                            <input type="text" class="form-control"  placeholder="请输入预约单流水号" name="checkAno" value="${qo.checkAno}">
                        </div>
                                <div class="form-group">
                                    <label>预约业务大类</label>
                                    <select class="form-control"  id="categoryId" name="checkCategoryId">
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>预约单状态</label>
                                    <select class="form-control" id="status" name="checkStatus" >
                                        <option value="">全部</option>
                                        <option value="0">待确认</option>
                                        <option value="1">履行中</option>
                                        <option value="2">消费中</option>
                                        <option value="3">废弃</option>
                                        <option value="4">归档</option>
                                    </select>
                                    <script>
                                        $('#status').val(${qo.checkStatus})
                                    </script>
                                </div>
                                <div class="form-group">
                                    <label>门店查询</label>
                                    <select class="form-control"  id="businessId" name="checkBusiness">
                                        <option value="">请选择门店</option>
                                        <#list businesses as b>
                                            <option value="${b.id}">${b.name}</option>
                                        </#list>
                                    </select>
                                    <script>
                                        $('#businessId').val(${qo.checkBusiness})
                                    </script>
                                </div>
                                <div class="form-group">
                                    <label>客户名称</label>
                                    <input type="text" class="form-control"  name="checkContactName" placeholder="请输入客户名称" value="${qo.checkContactName}">
                                </div>

                                <div class="form-group">
                                    <label>客户手机号</label>
                                    <input type="text" class="form-control" name="checkContactTel" placeholder="请输入客户手机号" value="${qo.checkContactTel}" >
                                </div>

                                <br/>
                                <br/>
                        <div class="form-group">
                            <label>预约时间查询：</label>
                            <input placeholder="请输入开始时间" type="text"  class="form-control input-dateTime-noss "  name="startTime" value="${(qo.startTime?string('yyyy-MM-dd'))!}" /> -
                            <input placeholder="请输入结束时间" type="text"  class="form-control input-dateTime-noss "  name="lastTime"  value="${(qo.lastTime?string('yyyy-MM-dd'))!}"/>
                        </div>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>

                        <a href="#" class="btn btn-success btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>

                </div>
                <div class="box-body table-responsive ">
                <table class="table table-hover table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>流水号</th>
                        <th>业务大类</th>
                        <th>预约说明</th>
                        <th>预约时间</th>
                        <th>客户名称</th>
                        <th>联系方式</th>
                        <th>预约门店</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#list PageInfo.list as a>
                    <tr>
                        <td>${a_index+1}</td>
                        <td>${a.ano}</td>
                        <td>${a.category.title}</td>
                        <td>${a.info}</td>
                        <td>${(a.createTime?string('yyyy-MM-dd'))!}</td>
                        <td>${a.contactName}</td>
                        <td>${a.contactTel}</td>
                        <td>${a.business.name}</td>
                        <td>${a.statusName}</td>
                        <td>
                            <a href="#" class="btn btn-info btn-xs btn-input" data-json='${a.toJson()}'>
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a class="btn btn-xs btn-primary btn-status" data-id="${a.id}" data-status="1"  >
                                <span class="glyphicon glyphicon-phone-alt" ></span> 确认预约</a>
                            <a class="btn btn-xs btn-danger btn-status" data-id="${a.id}" data-status="4" >
                                <span class="glyphicon glyphicon-remove" ></span> 取消预约</a>
                            <a href="#" class="btn btn-success btn-xs btn-consume"  data-ano="${a.ano}" data-id="${a.id}" >
                                <span class="glyphicon glyphicon-shopping-cart" ></span> 确认到店
                            </a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>
                    <!--分页-->
                    <#include "/common/page.ftl">
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>
<script>
    $(function () {
        //查询出业务大类
        $.get('/systemDictionaryItem/selectByTypeSn', {sn: 'business'}, function (data) {
            let str = '<option value="">请选择业务大类</option>';
            $.each(data, function (index, ele) {
                str += '<option value="' + ele.id + '">' + ele.title + '</option>'
            });
            $("#categoryId").html(str);
            $("#selectCategory").html(str);
            $('#categoryId').val(${qo.checkCategoryId})
        });
        //编辑页面的回显
        $('.btn-input').click(function () {
            var json = $(this).data('json');
            if (json) {
                $("input[name=id]").val(json.id);
                $("input[name=appointmentTime]").val(json.appointmentTime);
                $("input[name=contactName]").val(json.contactName);
                $("input[name=contactTel]").val(json.contactTel);
                $("select[name='business.id']").val(json.businessId);
                $("select[name='category.id']").val(json.categoryId);
                $("textarea[name=info]").html(json.info)
            }
            $('#editModal').modal('show')
        })
        //取消和确认按钮
        $('.btn-status').click(function () {
            var str = "是否确定客户赴约?";
            var id = $(this).data('id');
            var status = $(this).data('status');
            if (status == 4) {
                str = "是否确认客户取消预约?"
            }
            swal.fire({
                title: '警告',
                text: str,
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: '确认',
                cancelButtonText: '取消'
            }).then((result) => {
                if (result.value) { //确认
                    window.location.href = "/appointment/updateStatus?id=" + id + "&status=" + status
                }
            })
        })
        //确认到店按钮
        $('.btn-consume').click(function () {
            var str = "是否确定客户以到店?";
            var ano = $(this).data('ano');
            var id = $(this).data('id');
            swal.fire({
                text: str,
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: '确认',
                cancelButtonText: '取消'
            }).then((result) => {
                if (result.value) { //确认
                    swal.fire({
                        text: "客户有没有消费",
                        icon: 'warning',
                        showCancelButton: true,
                        confirmButtonText: '有,生成消费单',
                        cancelButtonText: '没有'
                    }).then((result) => {
                        if (result.value) { //确认 生成一个消费单,状态改为消费中
                            window.location.href = "/appointment/foundConsumption?id="+ id +"&status=2&ano="+ano
                        }else { //没有消费 改为状态归档
                            window.location.href = "/appointment/updateStatus?id=" + id + "&status=3"
                        }
                    })
                }
            })
        })
    })
</script>

<#-- 文件上传模态框 -->
<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/appointment/saveOrUpdate" method="post" >
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约门店：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="business.id" >
                                <#list businesses as b>
                                    <option value="${b.id}">${b.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label  ">预约时间：</label>
                        <div class="col-sm-7">
                            <input type="text"  class="form-control input-dateTime-noss " placeholder="请输入预约时间" name="appointmentTime"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">业务大类：</label>
                        <div class="col-sm-7">
                            <select class="form-control" id="selectCategory" name="category.id">
                                <option value="">请选择业务大类</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系人：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="contactName"
                                   placeholder="请输入联系人">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系电话：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="contactTel"
                                   placeholder="请输入联系电话">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约说明：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control" name="info"
                                      placeholder="请输入预约说明"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>


</body>
</html>
